package {
	import flash.display.Sprite;
	
	public class test3 extends Sprite {
		private var Evt1:String = "Evt1"; 
		private var Evt2:String = "Evt2"; 
		private var Evt3:String = "Evt3"; 
		private var Evt4:String = "Evt4"; 
		
		private var EvtDur:Object = {};
		
		private var FullSeq:Array = [];
		
		public function test3() {
			EvtDur[Evt1] = 2;
			EvtDur[Evt2] = 22;
			EvtDur[Evt3] = 46;
			EvtDur[Evt4] = 22;
			
			FullSeq = [Evt1, Evt2, Evt1, Evt3, Evt1, Evt4, Evt1, Evt3, Evt1, Evt4]; // неделя
			
			trace("new Date().getTime()", new Date().getTime());
			trace("new Date().toUTCString()", new Date().toUTCString());
			
			trace("getCurEvent: ", getCurEvent(new Date().getTime() / 1000));
		}
		
		/**
		 * 
		 * @param epochSeconds
		 * @return 
		 * 
		 */		
		public function getCurEvent(epochSeconds:uint):String {
			var date:Date = new Date(epochSeconds * 1000);
			var hours:uint = date.getHours();
			var day:uint = date.getDay() == 0 ? 7 : date.getDay(); 
			var index:uint = hours + Math.max(day - 1, 0) * 24; 
			
			trace("hours", hours, "day", day, "index", index);
			
			if((day == 7 && hours >= 23) || (day == 1 && hours <= 1)) {
				return Evt1;
			} else {
				for (var i:uint = 0, sum:uint = 0; i < FullSeq.length; i++) {
					if(index <= (sum += EvtDur[FullSeq[i]])) {  
						return FullSeq[i];
					}
				}
			}

			return "";
		}
	}
}